package com.note.chh.notebook.UI.enjoy.singerlist;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.note.chh.notebook.Adapter.SingerListAdapter;
import com.note.chh.notebook.Model.SingerListModel;
import com.note.chh.notebook.R;
import com.note.chh.notebook.UI.base.BaseActivity;
import com.note.chh.notebook.Uitls.ItemDivider;
import com.note.chh.notebook.Uitls.UserUtil;
import com.note.chh.notebook.Uitls.gson.GsonImpl;
import com.qmuiteam.qmui.widget.QMUITopBar;

import java.util.List;

import butterknife.BindView;

//歌手列表
public class SingerListActivity extends BaseActivity {

    @BindView(R.id.topbar)
    QMUITopBar topbar;
    @BindView(R.id.mRecycle_singerList)
    RecyclerView mRecycleSingerList;
    private BaseQuickAdapter singerListAdapter;
    private int classId = 0;

    @Override
    public void initTopBar() {
        super.initTopBar();
        topbar.setBackgroundColor(getResources().getColor(R.color.colorTransparent));
        topbar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    @Override
    protected int bindLayout() {
        return R.layout.activity_singer_list;
    }

    @Override
    public void initView() {

        QMUIStatusBar(SingerListActivity.this);

        Bundle bundle = getIntent().getExtras();
        classId = bundle.getInt("classId");
        String className = bundle.getString("className");
        topbar.setTitle(className);

        mRecycleSingerList.setLayoutManager(new GridLayoutManager(this,3));
        mRecycleSingerList.addItemDecoration(new ItemDivider().setDividerWith(SizeUtils.dp2px(10)).setDividerColor(getResources().getColor(R.color.colorTransparent)));
        singerListAdapter = new SingerListAdapter(R.layout.item_singer_list);
        singerListAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        mRecycleSingerList.setAdapter(singerListAdapter);

    }

    @Override
    public void initData() {
        getSingerList();
    }

    @Override
    public void initListener() {
        super.initListener();
        singerListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                SingerListModel.SingersBean.ListBean.InfoBean infoBean = (SingerListModel.SingersBean.ListBean.InfoBean) adapter.getData().get(position);

                Bundle bundle = new Bundle();
                bundle.putInt("Singerid",infoBean.getSingerid());
                bundle.putString("Singername",infoBean.getSingername());
                startActivity(SongListActivity.class,bundle);

            }
        });
    }

    //获取歌手列表
    private void getSingerList(){

        OkGo.<String>get("http://m.kugou.com/singer/list/"+classId+"?json=true")
                .tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {

                        SingerListModel singerListModel = GsonImpl.get().toObject(response.body(), SingerListModel.class);
                        List<SingerListModel.SingersBean.ListBean.InfoBean> info = singerListModel.getSingers().getList().getInfo();
                        singerListAdapter.setNewData(info);

                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);

                    }
                });
    }




}
